package com.dpp.mapper;

import com.dpp.entity.AddressBook;
import com.dpp.entity.Users;
import com.dpp.vo.OutOrderVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {

    @Insert("insert into users(openid,type) values " +
            "(#{openid},#{type})")
    void save(Users user);
    @Select("select * from users where openid = #{openid}")
    Users selectByOpenId(String openid);
    @Select("select t2.* from users t1,address_book t2 where t1.openid = t2.openid and t1.openid = #{openid} and t1.type = 1 and t2.is_default = 1")
    AddressBook selectByOpenid(String openid);

    @Select("select t1.order_times,t2.phone,t2.address from users t1,address_book t2 where t1.openid = t2.openid and t1.openid = #{openid} and t2.is_default = 1")
    OutOrderVO selectTimesAndDA(String openid);

    @Update("update users set order_times = order_times+1 where openid = #{openid}")
    void updateTimes(String openid);

    @Update("update users set order_times = order_times-1 where openid = #{currentId}")
    void updateCancelTimes(String currentId);
    @Update("update users  set type = #{type} where openid = #{openid}")
    void updataType(String openid, Integer type);



}
